package com.youngwang.system;

/**
 * 测试 java 父子类的类变量和方法的内存分配
 * @author youngwang
 *         Date: 2016/11/4
 */
public class BasePerson {
    public String name = "wang";

    public BasePerson(){
        System.out.println("BasePerson 的构造器");
    }

    public void display(){
        System.out.println(this.name);
    }
}

class SubPerson extends BasePerson {
    public String name = "yang";

    public SubPerson(){
        super();
        System.out.println("SubPerson 的构造器");
    }

    public void display(){
        System.out.println(this.name);
    }

    public static void main(String[] args) {
        SubPerson subPerson = new SubPerson();
        System.out.println(subPerson.name);
        subPerson.display();

        BasePerson basePerson = new SubPerson();
        // 对象的属性调用的是声明该引用类型的属性
        System.out.println(basePerson.name);
        basePerson.display();

        basePerson.name = "wangyang";
        System.out.println(basePerson.name);
        System.out.println(subPerson.name);
    }
}
